<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title></title>
</head>
<body>
<!--弹窗：教职工选择-->
<div th:fragment="tteacherinfoSel" class="modal inmodal fade" id="tteacherinfoSel_Modal"
     tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title">编辑</h4>
                <small class="font-bold"></small>
            </div>
            <div class="modal-body">
                    <div class="table-responsive">
                        <table id="tteacherinfoSel_table" class="table table-striped"></table>
                    </div>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="tteacherinfoSelObj.submitHandler()">
                    确定
                </button>
            </div>
        </div>
    </div>
<script type="text/javascript">
    $().ready(function () {
        tteacherinfoSelObj.initTable();
    })
    var tteacherinfoSelObj = new Object({
        dataListSelections: [],
        myTable: undefined,
        myModal: $('#tteacherinfoSel_Modal'),
        submitCallback: undefined,
        open: function (callback) {
            if(callback){
                this.submitCallback = callback;
            }
            this.myModal.modal('show')
        },
        submitHandler: function () {
            if(this.dataListSelections.length == 0){
                $.mySwalWarn('请选择人员');
                return;
            }
            if(this.submitCallback){
                this.submitCallback(this.dataListSelections.map(o=>{
                    return {'teacherId':o.id,'teacherName':o.name};
                }));
                this.myTable.bootstrapTable('uncheckAll');
                this.myTable.bootstrapTable('resetSearch');
                this.myModal.modal('hide')
            }
        },
        checkRowHander: function () {
            tteacherinfoSelObj.dataListSelections = tteacherinfoSelObj.myTable.bootstrapTable('getSelections');
        },
        refreshDataList: function () {
            tteacherinfoSelObj.myTable.bootstrapTable('refresh');
        },
        initTable: function () {
            tteacherinfoSelObj.myTable = $('#tteacherinfoSel_table').bootstrapTable({
                toolbar: ".toolbar",
                search: true,
                trimOnSearch: true,
                clickToSelect: true,
                pagination: true,
                sidePagination: 'server',
                url: '/zzsys/teacher/list',
                method: 'post',
                formatNoMatches: function () {  //没有匹配的结果
                    return '暂无数据';
                },
                queryParams: function (param) {
                    return param;
                },
                onCheck: function (row, $element) {
                    tteacherinfoSelObj.checkRowHander();
                },
                onUncheck: function (row, $element) {
                    tteacherinfoSelObj.checkRowHander();
                },
                onCheckAll: function (row, $element) {
                    tteacherinfoSelObj.checkRowHander();
                },
                onUncheckAll: function (row, $element) {
                    tteacherinfoSelObj.checkRowHander();
                },
                onCheckSome: function (row) {
                    tteacherinfoSelObj.checkRowHander();
                },
                onUncheckSome: function (row) {
                    tteacherinfoSelObj.checkRowHander();
                },
                columns: [{
                    title: '#',
                    align: 'center',
                    width: 50,
                    checkbox: true,
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                }, {
                    title: '工号',
                    field: 'workNo',
                    sortable: true,
                    sortName: 'WORK_NO_',
                    width: 100
                }, {
                    title: '姓名',
                    field: 'name',
                    width: 100
                }],
                responseHandler: function (res) {
                    return {
                        total: res.page.totalCount,
                        rows: res.page.list
                    };
                }
            });
        }
    })
</script>
</body>
</html>